menuList[3].onclick();

// 获取数据并渲染
current=1;
pageSize=10;
let result;

async function fun(flagOptions){
    result = await getData(current,pageSize);
    counts = result.data.totalCounts;
    console.log(counts);
    pages = result.data.totalPage;
    pageFun({
        current:current,
        pages:pages,
        counts:counts,
        flagOptions:flagOptions,
        pageSize:pageSize
    })
}
fun(0);
function getData(current,pageSize){
    return new Promise((resolve, reject) => {
        axios({
            url:'/admin/store/findAllBussiness',
            method:'GET',
            params:{
                page:current,
                size:pageSize
                }
            })
            .then(data => {
                decorateFun(data)
                console.log(data.data);
                resolve(data.data);
            })
            .catch(err => {
                console.log(err);
            })
    });
   
}


// 删除单个用户
let shopid;
let shopname;
function openDeleteStoreFun(e){
    e=e || window.event;
    var target=e.target || e.srcElement;
    shopid=target.getAttribute('name');
    shopname=target.getAttribute('shopName');
    pointFun({
        code:5,
        msg:"是否删除该店铺的申请信息"
    })
    console.warn(target.getAttribute('name'));
    console.warn(target.getAttribute('shopName'));
}
function deleteStoreFun(){
    axios({
        url:'/admin/store/deleteABussiness',
        method:'DELETE',
        params:{
            bussinessId:shopid
        }
    })
    .then(data => {
        console.log(data);
        if(data.data.code==20000){
            closeFunStore();
            fun(0);
            explain({
                code:1,
                msg:"删除成功",
                time:3000
            })
        }
    })
    .catch(err => {
        console.log(err);
    })
}
// 渲染页面
function decorateFun(data){
    let tbodyMenu = cl("tbodyMenu");
    let dataNums = cl("dataNums");
    let pageMessage = cl("pageMessage");
    let top = cl("top");
    let end;
    console.log(data);
    if(current==1){
        end=data.data.data.list.length;
    }else{
        end =parseInt(current-1)*parseInt(data.data.data.size)+parseInt(data.data.data.list.length);
    }
    dataNums.innerHTML = data.data.data.list.length;
    pageMessage.innerHTML = `第${(current-1)*data.data.data.size+1}到${end}条记录，共${data.data.data.totalCounts}条`;
    tbodyMenu.innerHTML ="";
    let i=0;
    for(let key of data.data.data.list){
        tbodyMenu.innerHTML += `
        <tr>
            <td>${key.shopName}</td>
            <td>${key.realName}</td>
            <td>${key.introduction}</td>
            <td>${key.time}</td>
            <td>${key.setting==0?'未审核':'已审核'}</td>
            <td>
                <a href="/admin/store/storeApply?bussiness=${key.businessId}">
                    <button class="btn detailBtn">
                        <i class=" iconfont xiangqing-"></i>
                    </button>
                </a>
                <button class="btn delBtn"><i name="${key.businessId}" onclick="openDeleteUserFun()" class="iconfont shanchu"></i></button>
                
            </td>
        </tr>
            `
            i++
        }
        top.innerHTML = `
        <p>
            当前共有<b>${data.data.data.list.length}</b>家店铺申请入住
         </p>
        
        `
}
// 输入框回车事件
function inputEnterFun(){
    console.log("a");
    if(event.keyCode == 13){
        searchByStorename()
    }
}

// 页面刷新
function reloadFun(){
    location.reload();
}

// 选择每页展示数量
function chooseSizeFun(){
    let selectNums = document.getElementById("selectNums");
    console.log(selectNums.children[1]);
    console.warn(selectNums.value);
    current = 1;
    pageSize =selectNums.value;
    fun(1);
    for(let i=0;i<selectNums.children.length;i++) {
        if(selectNums.children.length[i]==selectNums.value){
            selectNums.children.length[i].select="select";
        }
    }
}
// 关闭函数
function closeFunStore(){
    alertWindow = document.getElementsByClassName("alertWindow")[0];
    let covers = document.getElementsByClassName("covers")[0];
    covers.style.display = "none";
    alertWindow.style.display = "none";
}
